package com.example.javaui.slice.component;

import com.example.javaui.ResourceTable;
import com.example.javaui.Utils;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.colors.RgbColor;
import ohos.agp.components.ProgressBar;
import ohos.agp.components.Rating;
import ohos.agp.components.element.PixelMapElement;
import ohos.agp.components.element.ShapeElement;
import ohos.agp.utils.Color;
import ohos.global.resource.Resource;

public class ProgressBarSlice extends AbilitySlice {

    @Override
    protected void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_slice_component_progressbar);

        ProgressBar progressBar = (ProgressBar) findComponentById(ResourceTable.Id_progressbar);
        progressBar.setDividerLineColor(Color.WHITE); // 设置分割线颜色
        progressBar.setDividerLineThickness(10); // 设置分割线宽度

        ProgressBar progressBarIndeterminate = (ProgressBar) findComponentById(ResourceTable.Id_progressbar_indeterminate);
        progressBarIndeterminate.setIndeterminate(true); // 无限模式
        // 创建并设置无限模式元素
        ShapeElement element = new ShapeElement();
        element.setBounds(0,0,50,50);
        element.setRgbColor(new RgbColor(255,0,0));
        progressBarIndeterminate.setInfiniteModeElement(element);

        Rating rating = (Rating) findComponentById(ResourceTable.Id_rating_sec);
        rating.setGrainSize(0.5f);  // 最小的控制粒度。
        rating.setScore(3.5f); // 当前的评级分数
        rating.setIsOperable(false); // 设置是否可以交互。当此值为true时，则不可以操作。

        Resource resource = null;
        try {
            // 设置评级的背景：点亮的五角星
            rating.setFilledElement(new PixelMapElement(getResourceManager().getResource(ResourceTable.Media_ic_star_filled)));
            // 设置评级的背景：半点亮的五角星
            rating.setHalfFilledElement(new PixelMapElement(getResourceManager().getResource(ResourceTable.Media_ic_star_halffilled)));
            // 设置评级的背景：未点亮的五角星
            rating.setUnfilledElement(new PixelMapElement(getResourceManager().getResource(ResourceTable.Media_ic_star_unfilled)));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
